<?php
namespace app\manage\controller;
use think\Request;
use app\manage\controller\Base;
use app\manage\model\AdminOrder as MAdminOrder;

/**
 * @title order 订单相关信息接口|[管理端]
 * @description 与订单有关的信息
 
 * 卖家与订单有关的操作都要包含：
 * 分类型|待受理的订单、已受理订单、打包中的订单、配送中的订单、已到货订单、取消/退货订单
 * 投诉的订单列表
 * 订单结算|结算信息列表、未结订单、已结订单
 */
 
class AdminOrder extends Base
{
    /**
     * @title order/list 查询订单列表信息 GET
     * @description 说明：依据 user_id 订单列表信息 
     * @author 虾哥@2424899422@qq.com
     * @url order/list/
	 * @Turl api/user_order/lists
	 
	 * @param name:user_id type:int require:1 default:null other: desc:用户ID
	 * @param name:page type:int require:0 default:1 other: desc:当前页ID
	 * @param name:length type:int require:0 default:5 other: desc:当前页显示数量
	 *
	 * @return lists:购物车列表|参考备注信息@
     * @lists order_id:收货地址自增ID  goods_name:商品名称 is_check:是否选中 goods_count:商品数量 goods_thums:商品缩略图   goods_desc:商品描述 shop_price:商品价格 count_money:单类型商品价格(商品数量*商品价格) 
	 * @return total_money:选中商品总价格
	 *
	 * @remark 返回示例{"code":0,"message":"query order list success !","data":{"list":[{"order_id":2,"is_check":1,"goods_count":3,"goods_name":"ed","goods_thums":"ere","goods_desc":"","shop_price":"3.00","count_money":9},{"order_id":3,"is_check":1,"goods_count":2,"goods_name":"de","goods_thums":"efe","goods_desc":"","shop_price":"3.00","count_money":6},{"order_id":4,"is_check":1,"goods_count":2,"goods_name":"de","goods_thums":"efe","goods_desc":"","shop_price":"3.00","count_money":6}],"total_money":21}}
     */
    public function lists($user_id,$page,$length)
    {
		$return = array('code' => 0, 'message' => 'query order list success !', 'data' => array());
		$data = MAdminOrder::lists($user_id,$page,$length);
		if (empty($data)) {
            $return['code'] = 1;
            $return['message'] = 'query order list failed !';
            return $return;
        }
        $return['data'] = $data;
		return json($return);	
    }
	
	
	/**
     * @title order/cancel 取消订单 GET
     * @description 依据 address_ids 删除订单 | 【暂不支持批量删除】| 支持清空购物车
	 * @author 虾哥@2424899422@qq.com
	 * @url order/cancel/
	 * @Turl api/user_order/cancel
	 
	 * @param name:user_id type:int require:1 default:null other: desc: 用户ID
	 * @param name:order_id type:int require:1 default:null other: desc:收货地址自增ID集合
	 * @param name:is_all_clear type:int require:0 default:0 other: desc:是否清空|0否/1是|默认为0 
	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为删除行数
     *
     */
    public function cancel($order_id,$user_id,$is_all_clear) {
        $return = array('code' => 0, 'message' => 'delete order success !', 'data' => array());
		$data = MAdminOrder::cartDelete($order_id,$user_id,$is_all_clear);
		if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'delete order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	
    }
	


	/**
     * @title order/update 订单支付 POST
     * @description 依据 order_id 订单支付 
	 * @author 虾哥@2424899422@qq.com
	 * @url order/order_pay/
	 * @Turl api/user_order/order_pay
  
	 * @param name:user_id type:int require:1 default:null other: desc: 用户ID
	 * @param name:good_ids type:int require:1 default:null other: desc:商品ID
	 * @param name:is_check type:int require:1 default:1 other: desc:是否选中
	 * @param name:goods_count type:int require:1 default:1 other: desc:商品数量
	 * @param name:goods_attr_id type:int require:1 default:0 other: desc:商品属性ID

	 
	 * @return lists:返回影响行数@
     * @lists nums:0失败|大于0为更新行数
     */

    public function update() {
	   $data = Request::instance()->post();
	   $return = array('code' => 0, 'message' => 'update order success !', 'data' => array());
	   $data['create_time'] = time();
	   $data = MAdminOrder::cartUpdate($data);
	   if (empty($data)) {
			$return['code'] = 1;
			$return['message'] = 'update order failed !';
			$return['data']['nums'] = 0;
			return $return;
		}
		$return['data']['nums'] = $data;
		return json($return);	 
    }




}
